﻿/*
* 时间：2019年7月 
* 作者：潘意
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace EMRView.Extensions.Command
{
    public class HCCommandsEditor : UITypeEditor
    {
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            #region 暂时不在此处控制控件类型

            var x = context.Container.Components;
            if (!(context.Instance is ToolStripComboBox) && !(context.Instance is ToolStripButton))
            {
                MessageBox.Show("命令只能添加于下拉列表控件与按钮控件！");
                return value;
            }

            #endregion

            CommandEditor editor = new CommandEditor(value.ToString());
            if (editor.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                return editor.SelectedCommand;
            }
            else
            {
                return value;
            }
        }

        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }

        public override bool GetPaintValueSupported(ITypeDescriptorContext context)
        {
            return true;
        }

        public override bool IsDropDownResizable => true;

        public override void PaintValue(PaintValueEventArgs e)
        {
            var r = e.Bounds;
            if (e.Context.Instance is ToolStripButton)
            {
                var btn = (e.Context.Instance as ToolStripButton);
                e.Graphics.DrawImage((btn).Image, r);
            }
        }

    }
}
